package cn.edu.sdu.sduhour.controller;

import cn.edu.sdu.sduhour.entity.Report;
import cn.edu.sdu.sduhour.mapper.ReportMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("/rep")
public class ReportController {
    @Resource
    ReportMapper reportMapper;

    //查询某个人的报告
    /*传入：String openid;*/
    @PostMapping("/one")
    public List<Report> getOne(@RequestBody Report report) {
        return reportMapper.findOne(report);
    }

    //插入一条报告
    /*传入：
    * String openid;
    * String nickName;
    * String avatarUrl;*/
    @PostMapping("/add")
    public List<Report> addOne(@RequestBody Report report) {
        Random random = new Random();
        int result_num = random.nextInt(2) + 1;
        String result;
        if(result_num == 1) {
            result = "济南";
        }else if(result_num == 2) {
            result = "青岛";
        }else {
            result = "威海";
        }

        Random random1 = new Random();
        int attr_num = random1.nextInt(2) + 1;
        String attribute;
        if(attr_num == 1) {
            attribute = "追光天使";
        }else if(attr_num == 2){
            attribute = "守光神明";
        }else {
            attribute = "光之骑士";
        }
        report.setCity(result);
        report.setAttribute(attribute);
        reportMapper.addOne(report);
        return reportMapper.findOne(report);
    }

    //更新一条报告
    /*传入：
    * String openid;
    * String changeName;
    * int changeNum;*/
    @PostMapping("/upd")
    public List<Report> changeOne(@RequestBody Report report) {
        reportMapper.changeOne(report);
        return reportMapper.findOne(report);
    }

    //删除一条报告（管理员）
    /*传入：int id;*/
    @DeleteMapping("/del")
    public String delOne(@RequestBody Report report) {
        reportMapper.delOne(report);
        return "success";
    }
}
